import type { UserInfo } from '@vben/types';

import { authRequestClient } from '#/api/request';

/**
 * 获取用户信息
 */
export async function getUserInfoApi(): Promise<UserInfo> {
  const response = await authRequestClient.get('/api/v1/auth/me');
  
  // 映射后端字段到前端期望的字段
  const backendUser = response.data;
  const userInfo: UserInfo = {
    id: backendUser.id,
    loginName: backendUser.login_name,
    fullName: backendUser.full_name,
    tenantId: backendUser.tenant_id,
    avatar: backendUser.avatar || '',
    roles: backendUser.roles?.map((role: any) => role.name) || [],
    homePath: '/dashboard', // 设置默认主页路径
    ...backendUser, // 保留其他字段
  };
  
  return userInfo;
}
